import sys
import json

def calculate(a, b, operation):
    """执行数学运算"""
    if operation == "add":
        return a + b
    elif operation == "subtract":
        return a - b
    elif operation == "multiply":
        return a * b
    elif operation == "divide":
        return a / b if b != 0 else "Error: Division by zero"
    else:
        return "Error: Unknown operation"

if __name__ == "__main__":
    try:
        # 从命令行参数获取输入
        a = float(sys.argv[1])
        b = float(sys.argv[2])
        operation = sys.argv[3]

        result = calculate(a, b, operation)

        # 返回JSON格式结果
        output = {
            "status": "success",
            "result": result,
            "operation": operation,
            "operands": [a, b]
        }
        print(json.dumps(output))

    except Exception as e:
        error_output = {
            "status": "error",
            "message": str(e)
        }
        print(json.dumps(error_output))